package com.ctsi.ssdc.controller.front;

import com.ctsi.ssdc.common.R;
import com.ctsi.ssdc.constants.SortedMapConstant;
import com.ctsi.ssdc.entity.Excel02;
import com.ctsi.ssdc.entity.SocialRetailSales;
import com.ctsi.ssdc.service.Excel02Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 2分区镇一般公共预算收入(Excel02)表控制层
 *
 * @author makejava
 * @since 2023-02-20 13:03:31
 */
@RestController
@RequestMapping("excel/02/front/")
public class Excel02FrontController {
    /**
     * 服务对象
     */
    @Resource
    private Excel02Service excel02Service;

    @GetMapping("view")
    public R view(@RequestParam int year, @RequestParam int month) {
        List<Excel02> allInfoList = excel02Service.queryByTime(year, month);
        if(allInfoList == null || allInfoList.isEmpty()) return R.miss("不存在该信息");
        Excel02 total =  null;
        Excel02 zhou_zhuang = null; // 周庄
        Excel02 dian_shan_hu = null; // 淀山湖
        Excel02 jin_xi = null; // 锦溪
        List<Excel02> fiexedList = new ArrayList<>();
        List<Excel02> sortedList = new ArrayList<>();
        for (Excel02 industry : allInfoList) {
            switch (industry.getIndicators()) {
                case "全市总计":
                    total = industry;
                    break;
                case "周庄镇":
                    zhou_zhuang = industry;
                    break;
                case "淀山湖镇":
                    dian_shan_hu = industry;
                    break;
                case "锦溪镇":
                    jin_xi = industry;
                    break;
                default:
                    fiexedList.add(industry);
                    sortedList.add(industry);
            }
        }
        fiexedList.sort(Comparator.comparingInt(a -> SortedMapConstant.get(a.getIndicators())));
        return R.ok().data("total", total).data("zhou_zhuang", zhou_zhuang)
                .data("dian_shan_hu", dian_shan_hu).data("jin_xi", jin_xi)
                .data("fiexedList", fiexedList).data("sortedList", sortedList);
    }

}

